package com.nmsl.membership.controller;

import java.lang.reflect.Member;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.membership.domain.Membership;
import com.nmsl.membership.service.IMembershipService;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.common.core.page.TableDataInfo;

/**
 * 会员表Controller
 * 
 * @author liuyan
 * @date 2025-02-14
 */

//会员列表
@RestController
@RequestMapping("/membership/membership")
public class MembershipController extends BaseController
{
    @Autowired
    private IMembershipService membershipService;

    /**
     * 查询会员表列表
     */
//    @PreAuthorize("@ss.hasPermi('membership:membership:list')")
//    @GetMapping("/list")
//    public TableDataInfo list(Membership membership)
//    {
//        startPage();
//        List<Membership> list = membershipService.selectMembershipList(membership);
//        return getDataTable(list);
//    }
    @PreAuthorize("@ss.hasPermi('membership:membership:list')")
    @GetMapping("/list")
    public TableDataInfo list(Membership membership)
    {
        startPage();
        List<Membership> list = membershipService.selectMembershipList(membership);
        return getDataTable(list);
    }

    /**
     * 导出会员表列表
     */
    @PreAuthorize("@ss.hasPermi('membership:membership:export')")
    @Log(title = "会员表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Membership membership)
    {
        List<Membership> list = membershipService.selectMembershipList(membership);
        ExcelUtil<Membership> util = new ExcelUtil<Membership>(Membership.class);
        util.exportExcel(response, list, "会员表数据");
    }

    /**
     * 获取会员表详细信息
     */
    @PreAuthorize("@ss.hasPermi('membership:membership:query')")
    @GetMapping(value = "/{membershipId}")
    public AjaxResult getInfo(@PathVariable("membershipId") Long membershipId)
    {
        return success(membershipService.selectMembershipByMembershipId(membershipId));
    }

    /**
     * 新增会员表
     */
    @PreAuthorize("@ss.hasPermi('membership:membership:add')")
    @Log(title = "会员表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Membership membership)
    {
        return toAjax(membershipService.insertMembership(membership));
    }

    /**
     * 修改会员表
     */
    @PreAuthorize("@ss.hasPermi('membership:membership:edit')")
    @Log(title = "会员表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Membership membership)
    {
        return toAjax(membershipService.updateMembership(membership));
    }

    /**
     * 删除会员表
     */
    @PreAuthorize("@ss.hasPermi('membership:membership:remove')")
    @Log(title = "会员表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{membershipIds}")
    public AjaxResult remove(@PathVariable Long[] membershipIds)
    {
        return toAjax(membershipService.deleteMembershipByMembershipIds(membershipIds));
    }
}
